package com.baba.client.controller;

import cn.hutool.json.JSONObject;
import com.baba.bracelet.base.BaseApiService;
import com.baba.client.entity.ClientUser;
import com.baba.client.service.impl.ClientUserServiceImpl;
import com.baba.client.utils.IpUtil;
import com.baba.client.utils.ObjectUtils;
import com.baba.client.utils.retruns.ResponseResult;
import com.baba.client.utils.retruns.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by cengyujun on 2020/6/9 5:37 下午
 *
 */
@CrossOrigin
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class ClientUserController extends BaseApiService<JSONObject> {
    @Autowired
    private ClientUserServiceImpl clientUserService;

    @ApiOperation(value="登入接口", notes="用户登入")
    @ApiImplicitParams({
            @ApiImplicitParam (dataType = "String",name = "userName",value = "账号",required = true),
            @ApiImplicitParam(dataType = "String",name = "userPassword",value = "密码",required = true)
    })
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResponseResult login(String userName , String userPassword, HttpServletRequest request, HttpServletResponse response) throws IOException {
                 if (ObjectUtils.isEmpty(userName)||ObjectUtils.isEmpty(userName))
                     return ResponseResult.failure(ResultCode.NULL_ERR);

        return  clientUserService.login(userName,userPassword,request);

    }

    /**
     *
     * @param clientUser
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
//            @ApiImplicitParam (dataType = "String",name = "user_name",value = "用户名 传ClientUser对象",required = true),
//            @ApiImplicitParam (dataType = "String",name = "user_password",value = "密码",required = true),
//            @ApiImplicitParam (dataType = "String",name = "user_photo_url",value = "用户头像",required = true),
//            @ApiImplicitParam (dataType = "int",name = "user_grade",value = "用户权限等级（1：超级管理员 '''以此推类）",required = true),
//            @ApiImplicitParam (dataType = "String",name = "user_dep",value = "部门类型",required = true),
//            @ApiImplicitParam (dataType = "int",name = "user_sex",value = "用户性别",required = true)
    @ApiOperation(value="添加用户", notes="ClientUser")
    @RequestMapping(value="/addUser", method = RequestMethod.POST)
    //String user_name, String user_password,String user_photo_url, int user_grade,String  user_dep ,int user_sex
    public ResponseResult addUser(ClientUser clientUser,HttpServletRequest request, HttpServletResponse response) throws IOException {
            if (ObjectUtils.isEmpty(clientUser))
                return ResponseResult.failure(ResultCode.NULL_ERR);

        return  clientUserService.addUser(clientUser);

    }

    @ApiOperation(value="查询系统用户", notes="查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pageNo",value="当前页",dataType="int", paramType = "query"),
            @ApiImplicitParam(name="pageSize",value="分页大小",dataType="int", paramType = "query"),
            @ApiImplicitParam(name="placeName",value="工棚名称",dataType="String", paramType = "query")
    })
    @RequestMapping(value="/listUserAll", method = RequestMethod.POST)
    public ResponseResult listUserAll() throws  IOException{

        return  clientUserService.queryAll();
    }
    @ApiOperation(value="修改用户信息", notes="修改")
    @RequestMapping(value = "/updetaUser",method =RequestMethod.POST)
    public  ResponseResult updetaUser(ClientUser clientUser){
        if (ObjectUtils.isEmpty(clientUser))
            return ResponseResult.failure(ResultCode.NULL_ERR);
        return  clientUserService.updateUser(clientUser);
    }

    @ApiOperation(value="删除用户信息", notes="删除")
    @RequestMapping(value = "/deletUser",method =RequestMethod.POST)
    public  ResponseResult deletUser(ClientUser clientUser){
        if (ObjectUtils.isEmpty(clientUser))
            return ResponseResult.failure(ResultCode.NULL_ERR);
        return  clientUserService.deletUser(clientUser);
    }






}

 //